<?php
//alter table tblProduct add fulltext ftiProducts(Product,Description,ExtraDescription)
include (MODULE . "/action/qrySearchProduct_Customer");
//echo "<!-- SQL nl2br($strSQL) -->";	
/*
	collect all data from previous search.
	This long winded way is being used to overcome a bug that occurred when navigating
	with onSubmit. 

*/
	if($txtProduct){
		$arrSearchFields['txtProduct'] = $txtProduct;
	}
	
	if($txtOwnProductCode){
		$arrSearchFields['txtOwnProductCode'] = $txtOwnProductCode;
	}
	
	if($cboCategory){
		$arrSearchFields['cboCategory'] = $cboCategory;
	}
	
	if($cboSubCategory){
		$arrSearchFields['cboSubCategory'] = $cboSubCategory;
	}

	
	$arrNext = $arrSearchFields;
	$arrNext['strDirection'] = "Next";
	
	$arrPrev = $arrSearchFields;
	$arrPrev['strDirection'] = "Prev";
	
	$arrCurrent = $arrSearchFields;
	$arrCurrent['strDirection'] = "Current";

	$arrSelectPage = $arrSearchFields;
	$arrSelectPage['strDirection'] = "SelectPage";
	
	//print_array($arrSelectPage);
	
	$RecordCount = $_SESSION['sesProductSearchRecord'];
	if($_SESSION['sesLastLine'] > 0)
	{
		$intPageNumber = ($_SESSION['sesFirstLine'] + $_SESSION['sesLastLine'])/$_SESSION['sesLastLine'];//Current Page Number
		$intPages =  ceil($RecordCount / $_SESSION['sesLastLine']);//Total number of pages
	}else{
		$intPageNumber = 1;
		$intPages = 1;
	}

	if($intPageNumber > 1){
		if(($intPageNumber == $intPages) && ($intPages >10)){
			$intFirstPageLink = $intPages - 10;
			//echo "intFirstPageLink $intFirstPageLink<br/>";
		}else{
			$intFirstPageLink = $intPageNumber - 1;
		}
	}else{
		$intFirstPageLink = 1;
	}
	
	if(($intPages - $intFirstPageLink) <= 10 ){
		$intLastPageLink = $intPages;
	}else{
		$intLastPageLink = $intPageNumber + 9;
	}
	
	
if($myrow[0]){
$arrParagraph = explode("<NewParagraph>",$myrow["Description"]);
echo "
 <tr>
     <td>
         <table  width='100%' cellpadding='0' cellspacing='0' border='0' class='Normal' align='center'>
";

			include (MODULE . "/screen/NavigationLinks");

echo "
			<tr><td width='110' height='1'><img src='./images".SITE_SUFFIX."/space.gif' width='110' height='1' border='0' alt=''></td><td width='160' height='1'><img src='./images".SITE_SUFFIX."/space.gif' width='160' height='1' border='0' alt=''></td><td width='80' height='1'><img src='./images".SITE_SUFFIX."/space.gif' width='80' height='1' border='0' alt=''></td></tr>
				<tr>";
     	
		do {
			
			if((NO_PHOTO == "none") && ($myrow["Picture"]=="none")){
				$strCols = " colspan='2'";
			}else{
				$strCols = " colspan='1'";
echo "
				<td width='110' align='center' valign='top'>";
					
						if((!$myrow["Picture"])||($myrow["Picture"]=="none")){
							echo "
							<a href='" . ScreenURL("scrListProductItem",array('nProdID'=>$myrow[0]) ) . "' target='_blank'>
								<img src='./images/".NO_PHOTO."'  border='0' alt=\"".$myrow["ProductName"]." - click to enlarge\">
							</a>";					
						}else{
							// width='".PRODUCT_THUMBNAIL_WIDTH."' 
							echo "
							<a href='" . ScreenURL("scrListProductItem",array('nProdID'=>$myrow[0]) ) . "' target='_blank'>
								<img src='./images/product/thumbz/".$myrow["Picture"]."' border='0' alt=\"".$myrow["ProductName"]." - click to enlarge\" align='center'>
							</a>";
		           	    }
					
echo "				
				</td>";
			}
echo "
					<td align='left' $strCols>
						".$myrow["ProductName"]."
";
					
							if($myrow["UnitsInStock"] < "1"){
								echo "<div align='left' class='Small'><b>Temporarily out of stock</b></div>";
							}
						
							if ($myrow["QuantityPerUnit"]>1){
								echo "<div class='Small' align='left'>qty&nbsp;in pack&nbsp;:&nbsp;".$myrow["QuantityPerUnit"]."</div><br/>\n";
							}?>

						<p><span class='Small'><?=isset($myrow["Description"])?nl2br($myrow["Description"]):""?></span></p>
					</td>
					
					<td align='right'>
						&nbsp;<b><?=CURRENCY.$myrow["UnitPrice"]?></b><br/><?

						if($myrow["UnitPrice"]<$myrow["FullPrice"])
						{
							echo "<div align='right' class='Small'>RRP&nbsp;".$myrow["FullPrice"]."</div>";
							$intSaving = $myrow["FullPrice"]-$myrow["UnitPrice"];
							echo "<div align='right' class='Small'><b>Save&nbsp;&pound;".number_format($intSaving, 2, '.', '')."</b></div><br/>";
						}
						
						if($myrow["UnitsInStock"] > "0"){
							$arrCurrent['ACTION'] = "actAddItem";
							$arrCurrent['intItem'] = $myrow["ProductID"];
							$arrCurrent['nProdID'] = $myrow[0];
							print("<br/><a href=\"" . ScreenURL("scrListProductItem",$arrCurrent ) . "\"");
							echo "><img src='./images".SITE_SUFFIX."/addtobasket.gif'  border='0' alt='Add To Basket'><br/>";
							print("</a>\n");
						}
						
echo "				</td>
				</tr>
				<tr>	
					<td colspan='3'>
						<hr>
					</td>
				</tr>
";


		} while ($myrow = mysql_fetch_array($result));
		
		
			include (MODULE . "/screen/NavigationLinks");

}else{

	echo "<tr>";
		echo "<td colspan='3'>Your Search has returned no results. </td>";
	echo "</tr>\n";
}
echo "
			</table>
		</td>
	</tr>
";
?>
